package top.zuli.service;

import top.zuli.model.Customer;

public class CustomerList {
    private Customer[] customerList;
    private int total;
    public CustomerList(int length){
        this.customerList = new Customer[length];
    }
    public boolean add(Customer customer){
        if (this.total>=this.customerList.length){
            return false;
        }
        this.customerList[total++] = customer;
        return true;
    }
    public boolean delete(int index) {
        if(index>=this.total) {
            return false;
        }
        for(int i=index;i<total-1;i++) {
            customerList[i] = customerList[i+1];
        }
        customerList[--total] = null;
        return true;
    }
    public boolean modify(int index,Customer customer) {
        if(index>=this.total) {
            return false;
        }
        customerList[index] = customer;
        return true;
    }
    //获得所有客户信息
    public Customer[] getCustomerList() {
        Customer[] customers = new Customer[total];//5  0-4
        for(int i=0;i<customers.length;i++) {
            customers[i] = this.customerList[i];
        }
        return customers;
    }
    //获得客户数量
    public int getTotao() {
        return this.getTotao();
    }
    //通过下标查找指定用户
    public Customer getCustomer(int index) {
        if(index>=this.total) {
            return null;
        }
        return customerList[index];
    }
}
